package com.dyz.swordFingerOffer2;

public class Divide1 {
    // 使用解法代替加法
    public int divide(int a, int b) {
        //边界条件
        if(a==Integer.MIN_VALUE&&b==-1){
            return Integer.MAX_VALUE;
        }
        int sign =(a>0)^(b>0)?-1:1;
        a = Math.abs(a);
        b = Math.abs(b);

        int res = 0;
        for(int i=31; i>=0;i--){
            if((a>>>i)-b>=0){
                a-=(b<<i);
                res+=(1<<i);
            }
        }
        return sign == 1? res:-res;
    }
}
